package cn.edu.jmu.oelp.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 分段工具
 * @author Wen
 */
public class SplitContentUtils {
    private final String text;
    private List<String> list = new ArrayList<>();

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public SplitContentUtils(String text) {
        this.text = text;
        splitContent();
    }

    public void splitContent(){
        String temp;
        Pattern p = Pattern.compile("\\s+|\t|\r|\n");
        Matcher m = p.matcher(text);
        temp = m.replaceAll("。");
        p = Pattern.compile("。”");
        m = p.matcher(temp);
        temp = m.replaceAll("”");
        p = Pattern.compile("。+");
        m = p.matcher(temp);
        temp = m.replaceAll("。");
        list = Arrays.asList(temp.split("。"));
    }
}
